package com.gezi.admin.module.code.gentable.column;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gezi.admin.module.code.gentable.column.model.CodeGenTableColumnAddParamModel;
import com.gezi.admin.module.code.gentable.column.model.CodeGenTableColumnEditParamModel;
import com.gezi.admin.module.code.gentable.column.model.CodeGenTableColumnSearchModel;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @Author 格子代码
 * @createDate 2024/2/10 09:00
 * @contact 1424529270@qq.com
 */
@Service
public class CodeGenTableColumnService extends ServiceImpl<CodeGenTableColumnMapper, CodeGenTableColumnEntity> {

    public Page<Map> findByPage(Page page, CodeGenTableColumnSearchModel searchVo) {
        return baseMapper.findBySearchVo(page,searchVo);
    }

    public List<Map> findByList(CodeGenTableColumnSearchModel searchVo) {
        return baseMapper.findBySearchVo(searchVo);
    }

    /**
     * 添加 - 事务
     * @param paramModel
     */
    @Transactional(rollbackFor = Exception.class)
    public void add(CodeGenTableColumnAddParamModel paramModel) {

    }

    @Transactional(rollbackFor = Exception.class)
    public void edit(CodeGenTableColumnEditParamModel paramModel) {

    }

    @Transactional(rollbackFor = Exception.class)
    public void del(String id) {
        removeById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    public void dels(String[] ids) {
        for (String id : ids) {
            removeById(id);
        }
    }

    public List<CodeGenTableColumnEntity> findAllByGenTableId(String genTableId) {
        return list(Wrappers.<CodeGenTableColumnEntity>query().eq("gen_table_id",genTableId).orderByAsc("sort"));
    }

    public List<CodeGenTableColumnEntity> selectDbTableColumnsByName(String tableName) {
        return baseMapper.selectDbTableColumnsByName(tableName);
    }
}